/* @(#)GSManufactureCategoryAddAction.java    V0.1
 *
 * Project: GSdevelop
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-2-28
 *   严首骅         2009-5-31  添加荣爱接口
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.HashMap;

import org.apache.commons.beanutils.BeanUtils;

import system.LoginContext;

import com.hitrust.gs.bean.GSManufactureCategoryBean;
import com.hitrust.gs.business.GSManufactureCategoryProcessor;
import com.hitrust.gs.form.GSManufactureCategoryAddForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.util.exception.GSException;
import client.*;

/**
 * 新增产品种类记录
 */
public class GSManufactureCategoryAddAction extends GSBaseAction {

    public String execute(GSBaseForm aForm) throws Exception {
        GSManufactureCategoryAddForm tForm = (GSManufactureCategoryAddForm) aForm;
        try {
            GSManufactureCategoryBean tGSManufactureCategoryBean = new GSManufactureCategoryBean();
            if (!(tForm.getGs_upper_manufacture_category().equals("0"))) {
                tForm.setGs_upper_manufacture_category(tForm.getGs_upper_manufacture_category().substring(2));
            }
            BeanUtils.copyProperties(tGSManufactureCategoryBean, tForm);
            String tLevel = tForm.getGs_manufacture_level();
            if (tLevel.equals("3")) {
                tGSManufactureCategoryBean.setGs_manufacture_category_id2(tForm.getGs_upper_manufacture_category());
                String tManufactureId1 = GSBaseManager.getManufactureCategory(tForm.getGs_upper_manufacture_category());
                tGSManufactureCategoryBean.setGs_manufacture_category_id1(tManufactureId1);
            }
            if (tLevel.equals("2")) {
                tGSManufactureCategoryBean.setGs_manufacture_category_id1(tForm.getGs_upper_manufacture_category());
            }
            if (tLevel.equals("1")) {
                tGSManufactureCategoryBean.setGs_manufacture_category_id1(tForm.getGs_upper_manufacture_category());
            }

            // 不是从交易平台导入s

            tGSManufactureCategoryBean.setGs_is_tradeflat_manuf_category("1");
            LoginContext loginContext = (LoginContext) aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
            GSManufactureCategoryProcessor.addTask(tGSManufactureCategoryBean, loginContext);

            // 设置xml参数
            if (XMLSend.getInstance().isToRong()) {
                String actionName = "SubmitMaterialType";
                String dataName = "MaterialType";
                // 传输xml to 荣爱
                XMLSend.getInstance().submitMaterialTypeSendXML(actionName, dataName, tGSManufactureCategoryBean);

            }

        } catch (GSException err) {
            if (err.getCode() != null) {
                HashMap tMap = new HashMap();
                tMap.put("err", err.getMessage());
                aForm.getRequest().setAttribute("_error", tMap);
                aForm.getRequest().setAttribute("message", err.getMessage());
                aForm.getRequest().setAttribute("exception_code", err.getCode());
                aForm.getRequest().setAttribute("requery", "true");
                // throw new GSException(err.getMessage());
                return GSBaseConstants.FORWARD_ERROR;
            }
        }
        aForm.getRequest().setAttribute("message", "产品分类新增成功！");
        aForm.getRequest().setAttribute("requery", "true");
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
